home *** CD-ROM | disk | FTP | other *** search
/ Revista CD Expert 32 / CD Expert nº 32.iso / Army Men TiS / data1.cab / Required_Files / rules / ctf_ai.txt < prev    next >
Text File  |  1999-10-08  |  5KB  |  166 lines

  1. // this gets loaded on the host if the @1 army is AI controlled
  2.  
  3. // @1 = color to do AI for, @2 = color of enemy, @3 = value for @1Action variable
  4. macro ctf_ai_enemy 3
  5. {
  6.     // these events setup the @1Action variable
  7.  
  8.     // before attacking @2 make sure @2 is in the game and is not an ally
  9.     if @1SetCapture@2 testvar IsColorInGame @2 > 0 and IsAlly @1 @2 = 0 then
  10.         setvar @1Action @3,
  11.         trigger @1Capture@2,
  12.         trigger @1StartTimeOut
  13.  
  14.     // these events choose new actions if my flag is captured by an enemy
  15.  
  16.     if @1Capture@2 testvar @1Action = @3 then
  17.         order @1sarge1 follow @2flag1 inmode attack,
  18.         order @1 group 1 follow @1sarge1 inmode defend,
  19.         order @1 group 2 follow @2flag1 inmode attack,
  20.         order @1 group 3 follow @2flag1 inmode attack
  21.  
  22.     // these events choose new actions if my flag is captured by an enemy
  23.  
  24.     if pickedup @1flag1 by @2 testvar isAlly @1 @2 = 0 and @1Action < 5 then
  25.         setvar @1Action 4,
  26.         trigger @1Rescue@1
  27.  
  28.     // these events choose new actions if I capture an enemy flag
  29.  
  30.     if pickedup @2flag1 by @1 then
  31.         setvar @1Action 5,
  32.         trigger @1TakeFlagToBase
  33.  
  34.     // these events choose new actions if any other flag is captured by an enemy
  35.  
  36.     if pickedup @2flag1 testvar @1Action < 4 then
  37.         setvar @1Action @3,
  38.         trigger @1Capture@2
  39.  
  40. }
  41.  
  42. // @1 = color to do AI for, @2 = color of flag
  43. macro ctf_check_holding_flag 2
  44. {
  45.     if @1CheckIfHoldingFlags testvar hasitem @1sarge1 @2flag1 = 1 then
  46.         setvar @1Action 5,
  47.         trigger @1TakeFlagToBase
  48. }        
  49.  
  50. // @1 = color of army to do AI for, @2-@4 = other colors
  51. // @5 = letters to identify flagbase (e.g. "b" for blue, "gr" for grey)
  52. macro ctf_ai_macro 5
  53. {
  54.     // maintain a variable which knows when we are on our base pad
  55.     // this is used if we accidentally pickup our own flag and we are already on our base
  56.     variable @1OnBase 0
  57.  
  58.     if padon @1base then
  59.         setvar @1OnBase 1
  60.  
  61.     if padoff @1base then
  62.         setvar @1OnBase 0
  63.  
  64.     // This variable holds the current action for @1
  65.     // 0 means no action, 1 means goto @2 flag, 2 means goto @3 flag, 3 means goto @4 flag,
  66.     // 4 means rescue @1 flag, 5 means take flag to base
  67.     variable @1Action 0
  68.  
  69.     if startup1 then
  70.         triggerdelay 1000 @1ChooseNewAction,
  71.         triggerdelay 2000 @1RegularOrders
  72.  
  73.     if @1ChooseNewAction then
  74.         setvar @1Action 0,
  75.         trigger @1CheckIfHoldingFlags,
  76.         trigger @1ChooseAction
  77.  
  78.     // if it's time to choose a new action but we are currently holding a flag then we should
  79.     // always choose to take it to a base
  80.  
  81.     expand ctf_check_holding_flag ( @1 @1 )
  82.     expand ctf_check_holding_flag ( @1 @2 )
  83.     expand ctf_check_holding_flag ( @1 @3 )
  84.     expand ctf_check_holding_flag ( @1 @4 )
  85.         
  86.     // if @1 has no current action then pick a random action
  87.     // keep doing this until an action is set
  88.     if @1ChooseAction testvar @1Action = 0 then
  89.         trigger @1PickRandomAction,
  90.         triggerdelay 1000 @1ChooseAction
  91.  
  92.     if @1PickRandomAction then random
  93.         trigger @1SetCapture@2,
  94.         trigger @1SetCapture@3,
  95.         trigger @1SetCapture@4
  96.  
  97.     expand ctf_ai_enemy ( @1 @2 1 )
  98.     expand ctf_ai_enemy ( @1 @3 2 )
  99.     expand ctf_ai_enemy ( @1 @4 3 )
  100.  
  101.     // this event is for rescuing our own flag
  102.     if @1Rescue@1 testvar @1Action = 4 then
  103.         order @1sarge1 follow @1flag1 inmode attack,
  104.         order @1 group 1 follow @1sarge1 inmode defend,
  105.         order @1 group 2 follow @1flag1 inmode attack,
  106.         order @1 group 3 follow @1flag1 inmode attack
  107.  
  108.     // this event is for taking an enemy flag to my base
  109.     if @1TakeFlagToBase testvar @1Action = 5 then
  110.         order @1sarge1 goto @1base inmode attack,
  111.         order @1 group 1 follow @1sarge1 inmode defend,
  112.         order @1 group 2 goto near@1base inmode attack,
  113.         order @1 group 3 goto near@1base inmode attack
  114.  
  115.     // these events choose new actions if I rescue my own flag
  116.  
  117.     if pickedup @1flag1 by @1 testvar @1OnBase = 0 then
  118.         setvar @1Action 5,
  119.         trigger @1TakeFlagToBase
  120.  
  121.     if pickedup @1flag1 by @1 testvar @1OnBase = 1 then
  122.         triggerdelay 100 @1Drop@1Flag
  123.  
  124.     if @1Drop@1Flag then
  125.         dropitem @1sarge1 @1flag1 @5flagbase
  126.  
  127.     // these events chose a new action if we get an enemy flag to home base
  128.  
  129.     if padon @1base then
  130.         triggerdelay 1000 @1ChooseNewAction
  131.  
  132.     // if we get our own flag back to base then drop that too
  133.  
  134.     if padon @1base testvar hasitem @1sarge1 @1flag1 = 1 then
  135.         dropitem @1sarge1 @1flag1 @5flagbase
  136.  
  137.     // these events choose new actions if a sarge is killed
  138.  
  139.     if killed @1sarge1 then
  140.         triggerdelay 5000 @1ChooseNewAction
  141.  
  142.     // these are the standing order regardless of what mode sarge is in
  143.         
  144.     if @1RegularOrders then
  145.         setaimode @1 group 4 defend,
  146.         setaimode @1 group 5 defend,
  147.         order @1 group 7 goto near@1base inmode defend,
  148.         triggerdelay 5000 @1RegularOrders
  149.  
  150.     // timeout code - if mode has not changed for a while then change it
  151.  
  152.     variable @1TimeOutVar 0
  153.     variable @1LastTimeOutVar 1
  154.  
  155.     if @1StartTimeOut then
  156.         addvar @1TimeOutVar 1,
  157.         triggerdelay 120000 @1CheckTimeOut
  158.  
  159.     if @1CheckTimeOut testvar @1TimeOutVar = @1LastTimeOutVar then
  160.         trigger @1ChooseNewAction
  161.  
  162.     if @1CheckTimeOut testvar @1TimeOutVar <> @1LastTimeOutVar then
  163.         addvar @1LastTimeOutVar 1
  164. }
  165.  
  166.